/**
 * Created by lixiaodi on 2018/9/27 0027.
 */
mini.parse();
var form = new mini.Form("form1");
//保存
function SaveData() {
    var ids = form.getData();
    var groups = {
        groupId : ids.groupId,
        groupCode : ids.groupCode,
        groupName: ids.groupName,
        groupDesc : ids.groupDesc,
        logoUrl: ids.logoUrl,
        adreess : ids.adreess,
        telephone : ids.telephone,
        email : ids.email,
        updateDate : ids.updateDate
    };
    var jsonString = JSON.stringify(groups);

    $.ajax({
        url: ajaxUrl + "/GroupsController/save.do",
        type: 'POST',
        data: jsonString,
        contentType : "application/json",
        success: function (data) {
            CloseWindow("save");
        },
        error: function (jqXHR, textStatus, errorThrown) {
            CloseWindow();
        }
    });
}

////////////////////
//编辑
function SetData(data) {
    if (data.action == "edit") {
        //跨页面传递的数据对象，克隆后才可以安全使用
        data = mini.clone(data);
        $.ajax({
            url: ajaxUrl + "/GroupsController/findById.do?id=" + data.id,
            cache: false,
            success: function (data) {
                var o = mini.decode(data);
                form.setData(o.data);
                form.setChanged(false);
            }
        });
    }else if(data.action == "new"){
        console.log('new');
    }
}

function GetData() {
    var o = form.getData();
    return o;
}
function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
        if (confirm("数据被修改了，是否先保存?")) {
            return false;
        }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
}
function onOk(e) {
    SaveData();
}
function onCancel(e) {
    CloseWindow("cancel");
}